package com.didibigdata.Repositories;

import com.didibigdata.utils.JDBCTools;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by lkabb on 2020/6/7
 */
public class PointOutReadSizeRepository {

    public int getPointOutReadSize(String sqltime) {
        //日志
        Logger logger = LoggerFactory.getLogger(PointOutReadSizeRepository.class);
        logger.info("add PointOutReadSizeRepository logger successful!");

        ResultSet resultSetmysql = null;
        Connection connectionmysql = null;
        PreparedStatement statementmysql = null;
        int orderSetSize = 0;
        try {
            connectionmysql = JDBCTools.getConnection();
            statementmysql = connectionmysql.prepareStatement(sqltime);
            resultSetmysql = statementmysql.executeQuery();
            Set<String> orderSet = new HashSet<String>();
            while (resultSetmysql.next()) {
                orderSet.add(resultSetmysql.getString(3));
            }
            orderSetSize = orderSet.size();
            logger.info("orderSetSize: [{}]", orderSetSize);
        }catch (Exception e) {
            logger.error("PointOutReadSizeRepository SQLException: [{}]", e);
            e.printStackTrace();
        }finally {
            JDBCTools.releaseConnection(connectionmysql, statementmysql, resultSetmysql);
        }

        return orderSetSize;
    }
}
